﻿namespace EasyGo.Web.Controllers.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;
    using EasyGo.Web.Models;
    using EasyGo.Services;
    using EasyGo.Domain.Model;

    public class UserAccountViewModelController : ApiController
    {
        private readonly IUserAccountService userAccountService;

        private readonly ICompanyService companyService;

        public UserAccountViewModelController(IUserAccountService userAccountService, ICompanyService companyService)
        {
            this.userAccountService = userAccountService;
            this.companyService = companyService;
        }

        // GET api/useraccountviewmodel
        public HttpResponseMessage Get()
        {
            return Request.CreateResponse(HttpStatusCode.OK, new UserAccountViewModel() { Companies = companyService.GetCompantDictionary(), User = new UserAccount() });
        }

        // GET api/useraccountviewmodel/5
        public HttpResponseMessage Get(int id)
        {
            UserAccount one = userAccountService.GetUser(id);
            if (one == null)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, "User not found");
            }
            return Request.CreateResponse(HttpStatusCode.OK, new UserAccountViewModel() { Companies = companyService.GetCompantDictionary(), User = one });
        }
    }
}
